﻿Public Class clsHWSetting
    Public Function selectAllLHJ() As DataTable
        Dim szSql As String = String.Empty
        szSql &= "SELECT * FROM sf.t_hw_setting "
        szSql &= " WHERE factory_id =? AND workshop_id = ? AND equip_type_id = ? "
        szSql &= " AND deleted = false "
        szSql &= " ORDER BY equip_id ASC"
        Dim dt As DataTable = DBacs.ExecuteSql(szSql, -1, "TS", "LH", "LHJ")
        Return dt
    End Function

    Public Function selectAllLHJList(ty_name As String) As DataTable
        Dim szSql As String = String.Empty
        szSql &= "SELECT * FROM sf.t_hw_setting "
        szSql &= " WHERE factory_id =? AND workshop_id = ? AND equip_type_id = ? "
        szSql &= " AND deleted = false and status = ? "
        If ty_name.Equals("全部") = False Then
            szSql &= " and type_name = '" & ty_name & "'"
        End If
        szSql &= " ORDER BY equip_id ASC"
        Return DBacs.ExecuteSql(szSql, -1, "TS", "LH", "LHJ", "0")
    End Function

    Public Function selectAllLHJ(lhjList As String) As DataTable
        Try
            Dim szSql As String = String.Empty
            szSql = String.Empty
            szSql &= "SELECT * FROM sf.t_hw_setting where factory_id =? and workshop_id = ? "
            szSql &= " and equip_type_id = ? AND deleted = false "
            If String.IsNullOrEmpty(lhjList) = False Then
                szSql &= " and equip_id in (" & lhjList & ") "
            End If
            szSql &= " ORDER BY equip_id ASC"
            Dim dt As DataTable = DBacs.ExecuteSql(szSql, -1, "TS", "LH", "LHJ")
            Return dt
        Catch ex As Exception
            Throw New Exception("exception:" & ex.Message.ToString, ex)
        End Try
    End Function

    Public Function selectByTy(ws As String, type As String, type_name As String, status As String) As DataTable
        Dim szSql As String = String.Empty
        szSql &= "SELECT * "
        szSql &= "  FROM sf.t_hw_setting "
        szSql &= "  WHERE factory_id =? "
        szSql &= "  AND workshop_id = ? "
        szSql &= "  AND equip_type_id = ?"
        szSql &= "  AND type_name = ?"
        szSql &= "  AND status <> ?"
        szSql &= "  AND deleted = false"
        szSql &= "  ORDER BY workshop_id,equip_id "

        Dim dt As DataTable = DBacs.ExecuteSql(szSql, -1, "TS", ws, type, type_name, status)
        If IsNothing(dt) Then
            selectByTy = New DataTable
        Else
            selectByTy = dt
        End If
    End Function

    Public Function SetLHJstatus(status As String, lm As String, lhj As String) As Integer
        Dim szSql As String = "update sf.t_hw_setting set status = ? , last_minutes = ? where workshop_id = ? and equip_type_id = ? and equip_id = ?"
        Return DBacs.ExecuteUpdateSql(szSql, -1, status, lm, "LH", "LHJ", lhj)
    End Function

End Class
